/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

/**
 *
 * @author 阿椋世界第二可爱
 */
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
 
public class linkdb {
        public static final String db="com.mysql.jdbc.Driver";
        public static final String url="jdbc:mysql://localhost:3306/login";
        public static final String user="root";
        public static final String password="123456";
        private  Connection conn;
        
        public  void linkdatabase()
        {
			try {
				Class.forName(db);
				conn=DriverManager.getConnection(url,user,password);
				} catch (ClassNotFoundException e) {
				System.out.println("加载数据库类失败");
				} catch (SQLException e) {
				 System.out.println("连接数据库失败");
				}
        }
        
        public  Connection getconn()
        {
        	return conn;
        }
        
        public  void close()
        {
        	try {
				if(!conn.isClosed())conn.close();
			} catch (SQLException e) {
				System.out.println("关闭数据库连接失败");
			}
        }
}

